package com.fitso.wicket.page.journal;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;

import com.fitso.model.bean.journal.FoodJournalEntry;
import com.fitso.model.bean.nutrition.Food;
import com.fitso.model.bean.nutrition.Nutrient;

public class FoodJournalDataView extends DataView<FoodJournalEntry> {
	
	protected FoodJournalDataView(String id, IDataProvider<FoodJournalEntry> dataProvider) {
		super(id, dataProvider);
	}

	@Override
	protected void populateItem(Item<FoodJournalEntry> item) {
		final FoodJournalEntry entry = item.getModelObject();
		item.add(new Label("at", entry.getAt().toLocalTime().toString()));
		
		Food f = entry.getFood();
		item.add(new Label("name", f.getDescription().getCommonName()));
		item.add(new Label("size", f.getServing().getDescription()));
		item.add(new Label("calories", f.getCalories().getValue().toPlainString()));
		item.add(new Label("fats", getMass(f.getFats())));
		item.add(new Label("carbs", getMass(f.getCarbs())));
		item.add(new Label("protein", getMass(f.getProtein())));

	}
	
	protected String getMass(Nutrient n) {
		return n == null ? "0" : n.getMass().toString();
	}
}
